#include "NpcMgr.h"
#include "ZoneSvr.h"
#include "dbProto/dbTableDef.h"
#include "db_driver/db_driver.h"
#include "Scene.h"

using namespace su;
using namespace std;
using namespace proto;


NpcMgr& gNpcMgr = NpcMgr::Ins();

su::snowflake<> NpcMgr::s_createid;

Npc* NpcMgr::Find(uint64 id)
{
	auto it = m_id2Npc.find(id);
	L_COND(it != m_id2Npc.end(), nullptr);
	return it->second.get();
}

Npc* NpcMgr::CreateNpc()
{
	uint64 id = s_createid.nextid();
	auto it = m_id2Npc.find(id);
	L_COND(it == m_id2Npc.end(), nullptr);
	auto player= make_unique< Npc>();
	Npc* p = player.get();
	m_id2Npc.emplace(id, std::move(player));
	return p;
}



void NpcMgr::DelNpc(uint64 id, bool isSave)
{
	auto& m_id2Npc = NpcMgr::Ins().m_id2Npc;
	auto it = m_id2Npc.find(id);
	L_COND_V(it != m_id2Npc.end());
	LDEBUG("del npc ", it->second->Id());
	m_id2Npc.erase(it);
}


void NpcMgr::OnFiveMinute()
{
	for (auto& i : m_id2Npc)
	{
		//i.second->CheckDelPlayer();
	}
}


